package com.mapapp.flutter_mapapp.persenter;

import android.content.Context;

import com.mapapp.flutter_mapapp.bean.CheckCodeBean;
import com.mapapp.flutter_mapapp.bean.StepFloorBean;
import com.mapapp.flutter_mapapp.http.ActivityLifeCycleEvent;
import com.mapapp.flutter_mapapp.http.Api;
import com.mapapp.flutter_mapapp.http.HttpUtil;
import com.mapapp.flutter_mapapp.http.ProgressSubscriber;
import com.mapapp.flutter_mapapp.util.ToastUtils;
import com.mapapp.flutter_mapapp.view.FindPasswordViewInterfece;

import rx.subjects.PublishSubject;

public class FindPasswordPersenter {
    private static final String TAG = "FindPasswordPersenter";

    private FindPasswordViewInterfece mView;
    private Context mContext;
    private PublishSubject<ActivityLifeCycleEvent> lifecycleSubject;

    public FindPasswordPersenter(Context context , FindPasswordViewInterfece view,PublishSubject<ActivityLifeCycleEvent> lifecycleSubject){
        this.mContext = context;
        this.mView = view;
        this.lifecycleSubject = lifecycleSubject;
    }

    public void getCode(String phone){
        HttpUtil.getInstance().toSubscribe(Api.getApiService().getCode(phone),
                new ProgressSubscriber<String>(mContext,false) {
                    @Override
                    protected void _onNext(String data) {
                        mView.getCodeSuccess();
                    }

                    @Override
                    protected void _onError(String message) {
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }

    public void checkCode(String phone,String code){
        HttpUtil.getInstance().toSubscribe(Api.getApiService().checkCode(phone,code),
                new ProgressSubscriber<CheckCodeBean>(mContext,false) {
                    @Override
                    protected void _onNext(CheckCodeBean data) {
                        mView.checkCodeSuccess(data.getTempToken());
                    }

                    @Override
                    protected void _onError(String message) {
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }
}
